package com.leetcode.周赛.第235场;

import java.util.Arrays;
import java.util.Comparator;

/**
 * @author: xiaomi
 * @date: 2021/4/4
 * @description: 5723. 查找用户活跃分钟数
 * https://leetcode-cn.com/contest/weekly-contest-235/problems/finding-the-users-active-minutes/
 */
public class B_5723_查找用户活跃分钟数 {
    static B_5723_查找用户活跃分钟数 action = new B_5723_查找用户活跃分钟数();

    public static void main(String[] args) {
        test1();
        test2();
        test3();
    }

    static void test1() {
        //
        int[][] nums = {{0, 5}, {1, 2}, {0, 2}, {0, 5}, {1, 3}};
        int[] res = action.findingUsersActiveMinutes(nums, 5);
        System.out.println("res = " + Arrays.toString(res));
    }

    static void test2() {
        //

        //System.out.println("res = " + res);
    }

    static void test3() {
        //

        //System.out.println("res = " + res);
    }

    public int[] findingUsersActiveMinutes(int[][] logs, int k) {
        int len = logs.length;
        int[] res = new int[k];
        Arrays.sort(logs, new Comparator<int[]>() {
            @Override
            public int compare(int[] o1, int[] o2) {
                if (o1[0] != o2[0]) {
                    return o1[0] - o2[0];
                }
                return o1[1] - o2[1];
            }

        });
        int tempValue = 1;
        int index = 0;
        for (int i = 1; i < len; i++) {
//            if (i == k) {
//                break;
//            }
            if (logs[i][0] == logs[i - 1][0]) {
                //同个ID
                if (logs[i][1] == logs[i - 1][1]) {
                    continue;
                } else {
                    tempValue++;
                }
            } else {
                //不同ID
                res[tempValue - 1]++;
                tempValue = 1;
            }
        }
        res[tempValue - 1]++;
        return res;
    }

}
